﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using SaleStat.COM.Constant;
using SaleStat.BLL;
using SaleStat.COM.Exceptions;
using SaleStat.BLL.CM;
using System.Collections;
public partial class EditPwd : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!Page.IsPostBack)
            {
                //焦点设置
                txtUserName.Focus();

            }
        }
        catch (Exception ex)
        {
            ExceptionHandler(ex);
        }

    }
    #region 确定按钮事件
    /// <summary>
    /// 确定按钮事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void imgBtnSubmit_Click(object sender, ImageClickEventArgs e)
    {
        try
        {
            getUserInfo();
            f_Info(CommonConstant.OPERATIONS.EDITPWD, "修改密码");
          
        }
        catch (Exception ex)
        {
            ExceptionHandler(ex);


        }
    }
    #endregion

    #region 更新密码
    /// <summary>
    /// 验证此用户是否存在密码是否正确
    /// 更新密码
    /// </summary>
    public void getUserInfo()
    {
        //获取用户名和密码
        string strUserName = txtUserName.Text.ToString();
        string strPassWord = txtPassword.Text.ToString();

        //调用bll层方法获取用户信息
        Login_BLL loginBllService = new Login_BLL();
        DataTable dtUserInfo = loginBllService.getUserInfo(strUserName, strPassWord);
        if (dtUserInfo == null || dtUserInfo.Rows.Count == 0)
        {
            //业务异常
            //throw new BusinessException("用户名或密码错误!");
        }
        else
        {
                Login_BLL cmService = new Login_BLL();
                int intResult = 0;
                //调用bll层更新方法
                intResult = cmService.updateCustomerInfo(getModifyParam());
                if (intResult <= 0)
                {
                    //throw new BusinessException("密码更新失败!");
                }
                else
                {
                    //session中设置值
                    Session[SessionKeyConstant.SESSION_USERNAME] = strUserName;
                    Session[SessionKeyConstant.SESSION_USERID] = dtUserInfo.Rows[0]["UserID"].ToString();
                    Session[SessionKeyConstant.SESSION_PURVIEW] = dtUserInfo.Rows[0]["PermissionName"].ToString();
                    string strIpAddress = Request.UserHostAddress;
                    Session[SessionKeyConstant.SESSION_IPADDRESS] = strIpAddress;

                    Response.Write("<script> alert('密码更新成功!'); window.dialogArguments.location.href=window.dialogArguments.location.href;window.focus();window.close();</script>");


                   

                }
         
            


        }
       
    }
    #endregion

    #region 封装要修改的参数
    public ArrayList getModifyParam()
    {
        ArrayList arrParam = new ArrayList();
        string strCustomerName = txtUserName.Text.Trim();
        string strNewPwd = txt_twoPassword.Text.Trim();
        arrParam.Add(strNewPwd);
        arrParam.Add(strCustomerName);
        return arrParam;

    }
    #endregion

}
